#ifndef COMMON_THREAD_H
#define COMMON_THREAD_H


#include "error.h"
#include "SyncObject.h"

namespace common {

class ThreadStartRoutine {
  public:
    //To be called on thread start.
    inline virtual Error::code operator()() = 0;

};
//An interface for class to hold current platform specific handle to an application thread.
class Thread : public SyncObject {
  public:
    //Creates new thread as suspended.
    virtual Error::code Create(const ThreadStartRoutine & threadStart) = 0;

    //Sets this object to point current (caling thread).
    virtual Error::code Current() = 0;

    //Starts newly created thread.
    virtual Error::code Start() = 0;

    //Terminates Running thread. Should be used with causion.
    virtual Error::code Terminate() = 0;

    //Gives execution time, to another thread that is waiting.
    //Error if no waiting threads.
    virtual Error::code Switch() = 0;

    //Suspends current thread and yields for given time (in miliseconds)
    virtual Error::code Sleep(unsigned long int sleepTime) = 0;

    //Suspends the thread, or increases its suspension counter.
    virtual Error::code Suspend() = 0;

    //Resumes this thread, or reduces its suspension count.
    virtual Error::code Resume() = 0;

};

} // namespace common
#endif
